use iced::{
    button, Align, Button, Column, Element, HorizontalAlignment, Row, Sandbox, Text,
    VerticalAlignment,
};
use strum_macros::AsRefStr;

pub struct App1 {
    home_state: button::State,
    menu_a: button::State,
    menu_b: button::State,
    index: Idx,
}

#[derive(Debug, Clone, Copy, AsRefStr)]
pub enum Idx {
    Home,
    MenuA,
    MenuB,
}

#[derive(Debug, Clone, Copy)]
pub enum AppMsg {
    NavClicked(Idx),
}

impl Sandbox for App1 {
    type Message = AppMsg;

    fn new() -> Self {
        App1 {
            home_state: button::State::new(),
            menu_a: button::State::new(),
            menu_b: button::State::new(),
            index: Idx::Home,
        }
    }

    fn title(&self) -> String {
        "App1".into()
    }

    fn update(&mut self, message: Self::Message) {
        match message {
            AppMsg::NavClicked(i) => self.index = i,
        }
    }

    fn view(&mut self) -> Element<'_, Self::Message> {
        let home = Button::new(&mut self.home_state, Text::new("Home"))
            .on_press(AppMsg::NavClicked(Idx::Home));
        let menu_a = Button::new(&mut self.menu_a, Text::new("MenuA"))
            .on_press(AppMsg::NavClicked(Idx::MenuA));
        let menu_b = Button::new(&mut self.menu_b, Text::new("MenuB"))
            .on_press(AppMsg::NavClicked(Idx::MenuB));

        let nav = Column::new()
            .push(home)
            .push(menu_a)
            .push(menu_b)
            .spacing(10);

        let article = Text::new(self.index.as_ref())
            .horizontal_alignment(HorizontalAlignment::Center)
            .vertical_alignment(VerticalAlignment::Center);

        // let content = Column::new().push(article).spacing(10);

        Row::new()
            .push(nav)
            // .push(content)
            .push(article)
            .align_items(Align::Center)
            .into()
    }
}
